/****************************************************************************

  (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
      www.systec-electronic.com

  Project:      USB-CANmodul

  Description:  API interface of the Linux library SO-1068

  -------------------------------------------------------------------------

                $RCSfile:$

                $Author:$

                $Revision:$  $Date:$

                $State:$

                Build Environment:
                    GNU gcc

  -------------------------------------------------------------------------

  Revision History:

  2007/01/29 r.d.:  - recycling from first implementation of Sandro Stiller (HTWM)

****************************************************************************/


// Protection against mutliple including
#ifndef __USBCAN32_H__
#define __USBCAN32_H__

#include <stdio.h>
#include <unistd.h>
#include <asm/types.h>


/***************************************************************************/
/*                                                                         */
/*                                                                         */
/*          G L O B A L   D E F I N I T I O N S                            */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

#ifndef BOOL
    #define BOOL                    int
#endif

#ifndef BYTE
    #define BYTE                    __u8
#endif

#ifndef WORD
    #define WORD                    __u16
#endif

#ifndef DWORD
    #define DWORD                   __u32
#endif

#ifndef PUBLIC
    #define PUBLIC
#endif

#ifndef FALSE
    #define FALSE                   0
#endif

#ifndef TRUE
    #define TRUE                    1
#endif


//---------------------------------------------------------------------------
// macro definition
//---------------------------------------------------------------------------

// Filter calculation:

// Extended Frame:
// 33222222 22221111 11111100 00000000 \ (Bits 0-31 of AMR and ACR)
// 10987654 32109876 54321098 76543210 /
// -------- -------- -------- -----    > 29-Bit ID
//                                 -   > RTR-Bit        > GW-002 only
//                                 .-- > unused

// Standard Frame:
// 33222222 22221111 11111100 00000000 \ (Bits 0-31 of AMR and ACR)
// 10987654 32109876 54321098 76543210 /
// -------- ---                        > 11-Bit ID
//             -                       > RTR-Bit        > GW-002 only
//             .---- ........ ........ > unused
//                   --------          > Data byte 0    \ GW-002 only
//                            -------- > Data byte 1    /

// Macros for calculation of vallues for acceptance filter
#define USBCAN_SET_AMR(extended, can_id, rtr) \
    (extended) ?    ((((DWORD)can_id)<<3 )|((rtr)?0x000004:0)|0x00003) : \
                    ((((DWORD)can_id)<<21)|((rtr)?0x100000:0)|0xfffff)
#define USBCAN_SET_ACR(extended, can_id, rtr) \
    (extended) ?    ((((DWORD)can_id)<<3 )|((rtr)?0x000004:0)) : \
                    ((((DWORD)can_id)<<21)|((rtr)?0x100000:0))


//---------------------------------------------------------------------------
//
// Macro:       USBCAN_CALCULATE_AMR(), USBCAN_CALCULATE_ACR()
//
// Description: macros are calculating AMR and ACR using CAN-ID as parameter
//
//              NOTE:   This macros only are working if both from-id and
//                      to-id results a successive order of bits.
//              Example:
//                      from-id: 0x000  to-id:  0x01F   --> macros are working
//                      from-id: 0x400  to-id:  0x4FF   --> macros are working
//                      from-id: 0x101  to-id:  0x202   --> macros are NOT working
//
// A received CAN messages (with CAN-ID = RxID) will be accepted if the following
// condition is fulfilled:
//      ((~(RxID ^ ACR) | AMR) == 0xFFFFFFFF)
//
// Parameters:  extended    = [IN] if TRUE parameters from_id and to_id contains 29-bit CAN-ID
//              from_id     = [IN] first CAN-ID which should be received
//              to_id       = [IN] last CAN-ID which should be received
//              rtr_only    = [IN] if TRUE only RTR-Messages should be received, and rtr_too will be ignored
//              rtr_too     = [IN] if TRUE CAN data frames and RTR-Messages should be received
//
//              NOTE: Parameters rtr_only and rtr_too will be ignored Multiport 3004006,
//                    USB-CANmodul1 3204000 or USB-CANmodul2 3204002
//
// Return:      DWORD       = AMR or ACR
//
//---------------------------------------------------------------------------

#define USBCAN_CALCULATE_AMR(extended,from_id,to_id,rtr_only,rtr_too) \
    (extended) ?    ((((DWORD)(from_id)^(to_id))<<3 )|((rtr_too&!rtr_only)?0x000004:0)|0x00003) : \
                    ((((DWORD)(from_id)^(to_id))<<21)|((rtr_too&!rtr_only)?0x100000:0)|0xfffff)
#define USBCAN_CALCULATE_ACR(extended,from_id,to_id,rtr_only,rtr_too) \
    (extended) ?    ((((DWORD)(from_id)&(to_id))<<3 )|((rtr_only)?0x000004:0)) : \
                    ((((DWORD)(from_id)&(to_id))<<21)|((rtr_only)?0x100000:0))


//---------------------------------------------------------------------------
//
// Macro:       USBCAN_MAJOR_VER(), USBCAN_MINOR_VER(), USBCAN_RELEASE_VER()
//
// Description: macros to convert the version iformation from functions UcanGetVersionEx() and UcanGetFwVersion()
//
// Parameters:  ver     = [IN] extended version information as unsigned long (32 bit)
//
// Return:      major, minor or release version
//
//---------------------------------------------------------------------------

#define USBCAN_MAJOR_VER(ver)               ( (ver) & 0x000000FF)
#define USBCAN_MINOR_VER(ver)               (((ver) & 0x0000FF00) >> 8)
#define USBCAN_RELEASE_VER(ver)             (((ver) & 0xFFFF0000) >> 16)


//---------------------------------------------------------------------------
// const defines
//---------------------------------------------------------------------------

// maximum number of modules, that are supported (can not be changed!)
#define USBCAN_MAX_MODULES                  16

// With the function UcanInitHardware() the module is used, which
// is detected first. This define should only be used, in case only one module is connected
// to the computer.
#define USBCAN_ANY_MODULE                   255

// no valid USB-CAN Handle
#define USBCAN_INVALID_HANDLE               0xff

// pre-defined baudrate values for GW-001 and GW-002 (use function UcanInitCan() or UcanSetBaudrate())
#define USBCAN_BAUD_1MBit                   0x0014              // = 1000 kBit/s
#define USBCAN_BAUD_800kBit                 0x0016              // =  800 kBit/s
#define USBCAN_BAUD_500kBit                 0x001c              // =  500 kBit/s
#define USBCAN_BAUD_250kBit                 0x011c              // =  250 kBit/s
#define USBCAN_BAUD_125kBit                 0x031c              // =  125 kBit/s
#define USBCAN_BAUD_100kBit                 0x432f              // =  100 kBit/s
#define USBCAN_BAUD_50kBit                  0x472f              // =   50 kBit/s
#define USBCAN_BAUD_20kBit                  0x532f              // =   20 kBit/s
#define USBCAN_BAUD_10kBit                  0x672f              // =   10 kBit/s

// Frame format for a CAN message (bit oriented)
#define USBCAN_MSG_FF_STD                   0x00                // Standard Frame (11-Bit-ID)
#define USBCAN_MSG_FF_RTR                   0x40                // Remote Transmition Request Frame
#define USBCAN_MSG_FF_EXT                   0x80                // Extended Frame (29-Bit-ID)

// flags for informations in /proc/ucaninfo
#define UCAN_PROC_PRESENT                   1
#define UCAN_PROC_REMOVED                   2
#define UCAN_PROC_OPENED                    4

// Function return codes (encoding)
#define USBCAN_SUCCESSFUL                   0x00                // no error
#define USBCAN_ERR                          0x01                // error in library; function has not been executed
#define USBCAN_ERRCMD                       0x40                // error in module; function has not been executed
#define USBCAN_WARNING                      0x80                // Warning; function has been executed anyway
#define USBCAN_RESERVED                     0xc0                // reserved return codes (up to 255)

// Error messages, that can occur in the library
#define USBCAN_ERR_MAXMODULES               0x02                // the maximum number of open modules is exceeded
#define USBCAN_ERR_HWINUSE                  0x03                // a module is already in use
#define USBCAN_ERR_ILLVERSION               0x04                // the software versions of the module and library are incompatible
#define USBCAN_ERR_ILLHW                    0x05                // the module with the corresponding device number is not connected
#define USBCAN_ERR_ILLHANDLE                0x06                // wrong USB-CAN-Handle handed over to the function
#define USBCAN_ERR_ILLPARAM                 0x07                // wrong parameter handed over to the function
#define USBCAN_ERR_IOFAILED                 0x0a                // a request for the driver failed
#define USBCAN_ERR_CANNOTINIT               0x0d                // CAN-interface is not yet initialized

// Error messages, that the module returns during the command sequence
#define USBCAN_ERRCMD_NOTEQU                0x40                // the received response does not match with the transmitted command
#define USBCAN_ERRCMD_REGTST                0x41                // no access to the CAN controler possible
#define USBCAN_ERRCMD_ILLCMD                0x42                // the module could not interpret the command
#define USBCAN_ERRCMD_EEPROM                0x43                // error while reading the EEPROM occured
#define USBCAN_ERRCMD_RESERVED1             0x44
#define USBCAN_ERRCMD_RESERVED2             0x45
#define USBCAN_ERRCMD_RESERVED3             0x46
#define USBCAN_ERRCMD_ILLBDR                0x47                // illegal baudrate values for Multiport 3004006, USB-CANmodul1 3204000 or USB-CANmodul2 3204002 in BTR0/BTR1

// Warning messages, that can occur in library
// NOTE: These messages are only warnings. The function has been executed anyway.
#define USBCAN_WARN_NODATA                  0x80                // no CAN messages received
#define USBCAN_WARN_SYS_RXOVERRUN           0x81                // overrun in the receive queue of the driver (but this CAN message is successfuly read)


// macros to check the error code
#define USBCAN_CHECK_VALID_RXCANMSG(ret) \
    ((ret == USBCAN_SUCCESSFUL) || (ret > USBCAN_WARNING))      // checks if function UcanReadCanMsg..() returns a valid CAN message

#define USBCAN_CHECK_TX_OK(ret) \
    ((ret == USBCAN_SUCCESSFUL) || (ret > USBCAN_WARNING))      // checks if function UcanWriteCanMsg..() successfuly wrote CAN message(s)
                                                                //      While using UcanWriteCanMsgEx() the number of sent CAN messages can be less than
                                                                //      the numer of CAN messages which shold be sent. (see also USBCAN_WARN_TXLIMIT)
#define USBCAN_CHECK_TX_SUCCESS(ret) \
    (ret == USBCAN_SUCCESSFUL)                                  // checks if function UcanWriteCanMsgEx() successfuly wrote all CAN message(s)

#define USBCAN_CHECK_WARNING(ret) \
    (ret >= USBCAN_WARNING)                                     // checks if any function returns a warning

#define USBCAN_CHECK_ERROR(ret) \
    ((ret != USBCAN_SUCCESSFUL) && (ret < USBCAN_WARNING))      // checks if any function returns an error

#define USBCAN_CHECK_ERROR_CMD(ret) \
    ((ret >= USBCAN_ERRCMD) && (ret < USBCAN_WARNING))          // checks if any function returns an error from firmware in USB-CANmodul


// CAN status flags (is returned with function UcanGetStatus() )
#define USBCAN_CANERR_OK                    0x0000              // no error
#define USBCAN_CANERR_XMTFULL               0x0001              // Tx-buffer of the CAN controller is full
#define USBCAN_CANERR_OVERRUN               0x0002              // Rx-buffer of the CAN controller is full
#define USBCAN_CANERR_BUSLIGHT              0x0004              // Bus error: Error Limit 1 exceeded (refer to SJA1000 manual)
#define USBCAN_CANERR_BUSHEAVY              0x0008              // Bus error: Error Limit 2 exceeded (refer to SJA1000 manual)
#define USBCAN_CANERR_BUSOFF                0x0010              // Bus error: CAN controllerhas gone into Bus-Off state
#define USBCAN_CANERR_QRCVEMPTY             0x0020              // RcvQueue is empty
#define USBCAN_CANERR_QOVERRUN              0x0040              // RcvQueue overrun
#define USBCAN_CANERR_QXMTFULL              0x0080              // transmit queue is full
#define USBCAN_CANERR_REGTEST               0x0100              // Register test of the SJA1000 failed
#define USBCAN_CANERR_MEMTEST               0x0200              // Memory test failed

// USB error messages (is returned with UcanGetStatus..() )
#define USBCAN_USBERR_OK                    0x0000              // no error

// ABR and ACR for mode "receive all CAN messages"
#define USBCAN_AMR_ALL                      (DWORD) 0xffffffff
#define USBCAN_ACR_ALL                      (DWORD) 0x00000000

#define USBCAN_OCR_DEFAULT                  0x1A                // default OCR for standard GW-002
#define USBCAN_OCR_RS485_ISOLATED           0x1E                // OCR for RS485 interface and galvanic isolation
#define USBCAN_OCR_RS485_NOT_ISOLATED       0x0A                // OCR for RS485 interface without galvanic isolation


//---------------------------------------------------------------------------
// types
//---------------------------------------------------------------------------

// Typedef for the USB-CAN Handle
#ifndef UCHANDLE_DEFINED
    #define UCHANDLE_DEFINED
    typedef BYTE tUcanHandle;
#endif

// for further use
#define UCANRET         BYTE
#define UCANBYTE        BYTE
#define UCANWORD        WORD
#define UCANDWORD       DWORD


typedef struct
{
    DWORD   m_dwID;                         // CAN Identifier
    BYTE    m_bFF;                          // CAN Frame format (BIT7=1: 29BitID / BIT6=1: RTR-Frame / BIT5=1: Tx echo)
    BYTE    m_bDLC;                         // CAN Data Length Code
    BYTE    m_bData[8];                     // CAN Data
    DWORD   m_dwTime;                       // Time in ms

    // NOTE:
    // Value of m_dwTime only is valid for received CAN messages. It is ignored for
    // CAN messages to send. Bits 0 until 23 contains time and bits 24 until 31 are
    // reserved.

} tCanMsgStruct;

// Structure with the stati (Function: UcanGetStatus())
typedef struct
{
    WORD    m_wCanStatus;                   // [OUT] current CAN status
    WORD    m_wUsbStatus;                   // [OUT] current USB status

} tStatusStruct;

// Structure with the hardware properties of a USB-CANmodul (Function: UcanGetHardwareInfo())
typedef struct
{
    BYTE        m_bDeviceNr;                // [OUT] device number of the USB-CANmodul
    tUcanHandle m_UcanHandle;               // [OUT] USB-CAN-Handle assigned by the library
    DWORD       m_dwReserved;               // [OUT] reserved

    // values only for CAN channel 0
    BYTE        m_bBTR0;                    // [OUT] Bus Timing Register 0 (SJA1000)
    BYTE        m_bBTR1;                    // [OUT] Bus Timing Register 1 (SJA1000)
    BYTE        m_bOCR;                     // [OUT] Output Control Register (SJA1000)
    DWORD       m_dwAMR;                    // [OUT] Acceptance Mask Register (SJA1000)
    DWORD       m_dwACR;                    // [OUT] Acceptance Code Register (SJA1000)

    BYTE        m_bReserved1;               // [OUT]
    DWORD       m_dwReserved2;              // [OUT]

} tUcanHardwareInfo;


// version types for function UcanGetVersionEx()
typedef DWORD tUcanVersionType;

#define kVerTypeUserLib         0x00000001L // returns the version of the library



//---------------------------------------------------------------------------
// function prototypes
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
//
// Function:    LoadLibFunctions()
//
// Description: loads all library functions of the shared library
//
// Parameters:  pszLibName_p    = [in]  file name of the shared library
//
// Return:      int = error code
//                      0 = successful
//                     -1 = shared library not found
//                     -2 = a function of the shared library could not be load
//
//---------------------------------------------------------------------------

int PUBLIC LoadLibFunctions (const char* pszLibName_p);


//---------------------------------------------------------------------------
//
// Function:    UnloadLibFunctions()
//
// Description: unloads all library functions of the shared library
//
// Parameters:  void
//
// Return:      void
//
//---------------------------------------------------------------------------

void PUBLIC UnloadLibFunctions (void);


//---------------------------------------------------------------------------
//
// Function:    UcanSetDebugMode()
//
// Description: sets the debug mode for the library
//
// Parameters:  dwDbgLevel_p    = [IN]  debug level (undocumented)
//              pReserved_p     =       reserved - set to NULL
//              dwReserved_p    =       reserved - set to 0
//
// Return:      void
//
//---------------------------------------------------------------------------

void PUBLIC UcanSetDebugMode (DWORD dwDbgLevel_p, void* pReserved_p, DWORD dwReserved_p);


//---------------------------------------------------------------------------
//
// Function:    UcanGetVersionEx()
//
// Description: returns software version of different software modules
//
// Parameters:  VerType_p   = [IN] which version should be returned
//                                 (see tUcanVersionType for more informations)
//
// Returns:     software version
//
//                  format: Bit 0-7:    Version     (use USBCAN_MAJOR_VER() )
//                          Bit 8-15:   Revision    (use USBCAN_MINOR_VER() )
//                          Bit 16-31:  Release     (use USBCAN_RELEASE_VER() )
//
// NOTE: If returned version is zero, then value of VerType_p
//       is unknown or not supported or the file version could not be read.
//
//---------------------------------------------------------------------------

DWORD PUBLIC UcanGetVersionEx (tUcanVersionType VerType_p);


//---------------------------------------------------------------------------
//
// Function:    UcanInitHardware()
//
// Description: Initializes a USB-CANmodul with the device number x
//
// Parameters:  pUcanHandle_p   = [OUT] address pointing to the variable for the USB-CAN-Handle
//                                      should not be NULL!
//              bDeviceNr_p     = [IN]  device number of the USB-CANmodul
//                                      valid values: 0 through 254
//                                      USBCAN_ANY_MODULE: the first module that is found will be used
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_MAXMODULES
//                  USBCAN_ERR_ILLHW
//                  USBCAN_ERR_ILLPARAM
//                  USBCAN_ERR_IOFAILED
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanInitHardware (tUcanHandle* pUcanHandle_p, BYTE bDeviceNr_p, void* pReserved_p);


//---------------------------------------------------------------------------
//
// Function:    UcanGetHardwareInfo()
//
// Description: Returns the hardware information of an initialized USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              pHwInfo_p       = [OUT] pointer to hardware info structure
//                                      can not be NULL
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLPARAM
//                  USBCAN_ERR_ILLHANDLE
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanGetHardwareInfo (tUcanHandle UcanHandle_p, tUcanHardwareInfo* pHwInfo_p);


//---------------------------------------------------------------------------
//
// Function:    UcanSetDeviceNr()
//
// Description: Writes a new device number to the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              bDeviceNr_p     = [IN]  new device number (value range 0..254)
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLPARAM
//                  USBCAN_ERR_ILLHANDLE
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanSetDeviceNr (tUcanHandle UcanHandle_p, BYTE bDeviceNr_p);


//---------------------------------------------------------------------------
//
// Function:    UcanInitCan()
//
// Description: Initializes the CAN interface on the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              bBTR0_p         = [IN]  Baudrate Register 0 (SJA1000)
//              bBTR1_p         = [IN]  Baudrate Register 1 (SJA1000)
//              dwAMR_p         = [IN]  Acceptance Filter Mask (SJA1000)
//              dwACR_p         = [IN]  Acceptance Filter Code (SJA1000)
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_ILLHW
//                  USBCAN_ERR_IOFAILED
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanInitCan (tUcanHandle UcanHandle_p, BYTE bBTR0_p, BYTE bBTR1_p, DWORD dwAMR_p, DWORD dwACR_p);


//---------------------------------------------------------------------------
//
// Function:    UcanSetBaudrate()
//
// Description: Modifies the baudrate settings of the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              bBTR0_p         = [IN]  Baudrate Register 0 (GW-001/002 - Multiport 3004006,
//                                      USB-CANmodul1 3204000 or USB-CANmodul2 3204002 only standard values)
//              bBTR1_p         = [IN]  Baudrate Register 1 (GW-001/002 - Multiport 3004006,
//                                      USB-CANmodul1 3204000 or USB-CANmodul2 3204002 only standard values)
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanSetBaudrate (tUcanHandle UcanHandle_p, BYTE bBTR0_p, BYTE bBTR1_p);


//---------------------------------------------------------------------------
//
// Function:    UcanSetAcceptance()
//
// Description: Modifies the Acceptance Filter settings of the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              dwAMR_p         = [IN]  Acceptance Filter Mask (SJA1000)
//              dwACR_p         = [IN]  Acceptance Filter Code (SJA1000)
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanSetAcceptance (tUcanHandle UcanHandle_p, DWORD dwAMR_p, DWORD dwACR_p);


//---------------------------------------------------------------------------
//
// Function:    UcanResetCan()
//
// Description: Resets the CAN interface (Hardware-Reset, empty buffer, ...)
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanResetCan (tUcanHandle UcanHandle_p);


//---------------------------------------------------------------------------
//
// Function:    UcanReadCanMsg()
//
// Description: Reads one CAN message
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              pCanMsg_p       = [OUT] pointer to the CAN message structure
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERR_ILLPARAM
//                  USBCAN_WARN_SYS_RXOVERRUN
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanReadCanMsg (tUcanHandle UcanHandle_p, tCanMsgStruct* pCanMsg_p);


//---------------------------------------------------------------------------
//
// Function:    UcanWriteCanMsg()
//
// Description: Sends one CAN messages
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              pCanMsg_p       = [IN]  pointer to the CAN message structure
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERR_ILLPARAM
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanWriteCanMsg (tUcanHandle UcanHandle_p, tCanMsgStruct* pCanMsg_p);


//---------------------------------------------------------------------------
//
// Function:    UcanGetStatus()
//
// Description: Returns the state of the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//              pStatus_p       = [OUT] pointer to Status structure
//
//              bChannel_p      = [IN]  CAN channel (USBCAN_CHANNEL_CH0 or USBCAN_CHANNEL_CH1)
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_ILLPARAM
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanGetStatus (tUcanHandle UcanHandle_p, tStatusStruct* pStatus_p);


//---------------------------------------------------------------------------
//
// Function:    UcanDeinitCan()
//
// Description: Shuts down the CAN interface on the USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//                  USBCAN_ERR_CANNOTINIT
//                  USBCAN_ERRCMD_...
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanDeinitCan (tUcanHandle UcanHandle_p);


//---------------------------------------------------------------------------
//
// Function:    UcanDeinitHardware()
//
// Description: Deinitializes a USB-CANmodul
//
// Parameters:  UcanHandle_p    = [IN]  USB-CAN-Handle
//                                      Handle, which is returned by the function UcanInitHardware..()
//
// Returns:     result of the function
//                  USBCAN_SUCCESSFUL
//                  USBCAN_ERR_ILLHANDLE
//
//---------------------------------------------------------------------------

UCANRET PUBLIC UcanDeinitHardware (tUcanHandle UcanHandle_p);


#endif //__USBCAN32_H__

